package com.gitee.wsl.data.state.observing

import kotlin.time.ExperimentalTime
import kotlin.time.Instant

/**
 * Represent information when a replica was observed in last time.
 */
sealed interface ObservingTime : Comparable<ObservingTime> {

    data object Never : ObservingTime {
        override fun compareTo(other: ObservingTime): Int = when (other) {
            is Never -> 0
            is TimeInPast, is Now -> -1
        }
    }

    @OptIn(ExperimentalTime::class)
    data class TimeInPast(val time: Instant) : ObservingTime {
        override fun compareTo(other: ObservingTime): Int = when (other) {
            is Never -> 1
            is TimeInPast -> time.compareTo(other.time)
            Now -> -1
        }
    }

    data object Now : ObservingTime {
        override fun compareTo(other: ObservingTime): Int = when (other) {
            is Never, is TimeInPast -> 1
            Now -> 0
        }
    }
}